home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / pchr.prg < prev    next >
Text File  |  1991-08-17  |  8KB  |  230 lines

  1. /*
  2.  * File......: PCHR.PRG
  3.  * Author....: Jim Gale
  4.  * CIS ID....: 73670,2561
  5.  * Date......: $Date:   17 Aug 1991 15:40:16  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/pchr.prv  $
  8.  * 
  9.  * This is an original work by Jim Gale and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/pchr.prv  $
  16.  * 
  17.  *    Rev 1.2   17 Aug 1991 15:40:16   GLENN
  18.  * Don Caton fixed some spelling errors in the doc
  19.  * 
  20.  *    Rev 1.1   15 Aug 1991 23:06:00   GLENN
  21.  * Forest Belt proofread/edited/cleaned up doc
  22.  * 
  23.  *    Rev 1.0   12 Jun 1991 01:45:04   GLENN
  24.  * Initial revision.
  25.  *
  26.  */
  27.  
  28.  
  29. /*  $DOC$
  30.  *  $FUNCNAME$
  31.  *      FT_PCHR()
  32.  *  $CATEGORY$
  33.  *      String
  34.  *  $ONELINER$
  35.  *      Convert printer control codes
  36.  *  $SYNTAX$
  37.  *      FT_PCHR( <cString> )  ->  <cPrinterFormat>
  38.  *  $ARGUMENTS$
  39.  *       <cString> is the representation of the printer control codes in
  40.  *       text, numeric, hexadecimal, Epson command format, or any combination
  41.  *       separated by commas.
  42.  *  $RETURNS$
  43.  *       A character string of printer control codes.
  44.  *  $DESCRIPTION$
  45.  *       This function is useful for allowing the user to enter printer
  46.  *       control codes in text (enclosed in double quotes), numeric,
  47.  *       hexadecimal, or Epson commands preceded by a slash and returns
  48.  *       the printer control code equivalent.
  49.  *
  50.  *       NOTES"
  51.  *
  52.  *         - Combinations of text, numbers, hex, and commands must be
  53.  *            separated by commas ("A",27,&1B,/RESET).
  54.  *         - Text must be enclosed in double quotes ("x").
  55.  *         - Hexadecimal must be preceded by an ampersand (&1B).
  56.  *         - Epson commands, listed below, must be preceded by a forward
  57.  *            slash (/RESET).
  58.  *
  59.  *         Epson commands: (slash commands are specific to the Epson)
  60.  *
  61.  *           Job Control:
  62.  *
  63.  *           /RESET or /INIT   Reset or initialize the printer
  64.  *           /BELL  or /BEEP   Cause the printer's speaker to beep (not HS)
  65.  *           /CAN              Clear print buffers (not MX)
  66.  *           /SLOW             Set low speed mode (not CR, HS, MX)
  67.  *           /FAST             Cancel low speed mode (not CR, HS, MX)
  68.  *           /ONE              Select Unidirectional mode
  69.  *           /TWO              Select Directional mode
  70.  *           /ON               Activate printer
  71.  *           /OFF              Turn off printer
  72.  *
  73.  *           /FF or /EJECT     Form Feed
  74.  *
  75.  *           Page Control:
  76.  *
  77.  *           /1/6              Set 6 lines per inch
  78.  *           /1/8              Set 8 lines per inch
  79.  *           /SKIP             Set Skip perforation ON
  80.  *           /SKIPOFF          Set Skip perforation OFF
  81.  *
  82.  *           Font Selection and Manipulation:
  83.  *
  84.  *           /ITALIC           Select italic char. set  (only FX86, EX, LX,
  85.  *                                                           no LQ-1500, SX)
  86.  *           /GRAPHIC          Select graphic char. set (only FX86, EX, LX,
  87.  *                                                           no LQ-1500, SX)
  88.  *           /ROMAN            Choose Roman font
  89.  *           /SANS             Choose Sans Serif font
  90.  *           /DRAFT            Choose draft
  91.  *           /NLQ              Choose near letter quality
  92.  *           /PICA             Choose 10 chars per inch
  93.  *           /ELITE            Choose 12 chars per inch
  94.  *           /COND or /SI      Choose 15 chars per inch
  95.  *           /EMPH             Turn emphasize on
  96.  *           /EMPHOFF          Turn emphasize off
  97.  *           /SPANISH          Select spanish international char set
  98.  *           /USA              Select USA international char set
  99.  *
  100.  *  $EXAMPLES$
  101.  *       cSetUp := '27,116,1'
  102.  *       Set Print ON
  103.  *       ? FT_PCHR( cSetUp )      ->  (CHR(27)+CHR(116)+CHR(1))
  104.  *                                            <select Epson char. graphics>
  105.  *
  106.  *       ? FT_PCHR( '27,"x",0' )  ->  (CHR(27)+CHR(120)+CHR(0))
  107.  *                                         <Epson draft mode>
  108.  *
  109.  *       ? FT_PCHR( '&1B,"E"'  )  ->  (CHR(27)+CHR(69))   <HP reset>
  110.  *
  111.  *       ? FT_PCHR( '/ELITE,/NLQ' ) ->(CHR(27)+CHR(77)+CHR(27)+CHR(120)+CHR(1))
  112.  *                                <Epson elite & near letter quality>
  113.  *  $SEEALSO$
  114.  *
  115.  *  $END$
  116.  */
  117.  
  118.  
  119. Function FT_PCHR(c_nums)
  120.   Local c_ret:='', c_st:=0,c_part,c_st2,c_hex:="0123456789ABCDEF"
  121.   Local c_upper,c_t1,c_t2
  122.  
  123.    If Substr(c_nums,1,1)=','.or.Trim(c_nums)==''
  124.       Return ""
  125.    Endif
  126.  
  127.    c_nums := Trim(c_nums) + ",~,"
  128.    c_part := Substr(c_nums,c_st+1,At(",",Substr(c_nums,c_st+2)))
  129.  
  130.    Do While .not.(c_part=="~".or.c_part=="")
  131.       
  132.       If Substr(c_part,1,1)=Chr(34)
  133.       
  134.          c_st2:=At(Chr(34),Substr(c_part,2))+1
  135.          c_ret:=c_ret+Substr(c_part,2,c_st2-2)
  136.       
  137.       Elseif Substr(c_part,1,1)="&"
  138.       
  139.          c_upper=Upper(c_part)
  140.          c_t1=At(Substr(c_upper,2,1),c_hex)-1
  141.          If c_t1>-1
  142.             c_t2=At(Substr(c_upper,3,1),c_hex)-1
  143.             If c_t2>-1
  144.                c_t1=c_t1*16+c_t2
  145.             Endif
  146.             c_ret=c_ret+Chr(c_t1)
  147.          Endif
  148.       
  149.       ElseIf (Val(c_part)>0.and.Val(c_part)<256).or.c_part="0"
  150.       
  151.          c_ret=c_ret+Chr(Val(c_part))
  152.       
  153.       Else
  154.       
  155.          If Substr(c_part,1,1)="/"
  156.       
  157.             c_upper=Upper(c_part)
  158.  
  159.             Do Case
  160.                Case c_upper = '/GRAPHIC'
  161.                   c_ret = c_ret + Chr(27)+Chr(116)+Chr(1)
  162.                Case c_upper = '/ITALIC'
  163.                   c_ret = c_ret + Chr(27)+Chr(116)+Chr(0)
  164.                Case c_upper = '/PICTURE'
  165.                   c_ret = c_ret + Chr(27)+Chr(116)+Chr(1)+;
  166.                   Chr(27)+Chr(120)+Chr(1)+Chr(27)+Chr(107)+Chr(1)+;
  167.                   Chr(27)+Chr(77)+Chr(27)+'U'
  168.                Case c_upper = '/COND' .or. c_upper = '/SI'
  169.                   c_ret = c_ret + Chr(15)
  170.                Case c_upper = '/ROMAN'
  171.                   c_ret = c_ret + Chr(27)+Chr(107)+Chr(0)
  172.                Case c_upper = '/SANS'
  173.                   c_ret = c_ret + Chr(27)+Chr(107)+Chr(1)
  174.                Case c_upper = '/NLQ'
  175.                   c_ret = c_ret + Chr(27)+Chr(120)+Chr(1)
  176.                Case c_upper = '/DRAFT'
  177.                   c_ret = c_ret + Chr(27)+Chr(120)+Chr(0)
  178.                Case c_upper = '/ELITE'
  179.                   c_ret = c_ret + Chr(27)+Chr(77)
  180.                Case c_upper = '/PICA'
  181.                   c_ret = c_ret + Chr(27)+Chr(80)
  182.                Case c_upper = '/EMPHOFF'
  183.                   c_ret = c_ret + Chr(27)+Chr(70)
  184.                Case c_upper = '/EMPH'
  185.                   c_ret = c_ret + Chr(27)+Chr(69)
  186.                Case c_upper = '/1/6'
  187.                   c_ret = c_ret + Chr(27)+Chr(50)
  188.                Case c_upper = '/1/8'
  189.                   c_ret = c_ret + Chr(27)+Chr(48)
  190.                Case c_upper = '/SKIPOFF'
  191.                   c_ret = c_ret + Chr(27)+Chr(79)
  192.                Case c_upper = '/SKIP'
  193.                   c_ret = c_ret + Chr(27)+Chr(78)
  194.                Case c_upper = '/FF'.or.c_upper='/EJECT'
  195.                   c_ret = c_ret + Chr(12)
  196.                Case c_upper = '/INIT'.or.c_upper = '/RESET'
  197.                   c_ret = c_ret + Chr(27)+Chr(64)
  198.                Case c_upper = '/SPANISH'
  199.                   c_ret = c_ret + Chr(27)+Chr(82)+Chr(12)
  200.                Case c_upper = '/USA'
  201.                   c_ret = c_ret + Chr(27)+Chr(82)+Chr(0)
  202.                Case c_upper = '/ONE'
  203.                   c_ret = c_ret + Chr(27)+'U'+Chr(1)
  204.                Case c_upper = '/TWO'
  205.                   c_ret = c_ret + Chr(27)+'U'+Chr(0)
  206.                Case c_upper = '/FAST'
  207.                   c_ret = c_ret + Chr(27)+'s'+Chr(0)
  208.                Case c_upper = '/SLOW'
  209.                   c_ret = c_ret + Chr(27)+'s'+Chr(1)
  210.                Case c_upper = '/OFF'
  211.                   c_ret = c_ret + Chr(19)
  212.                Case c_upper = '/ON'
  213.                   c_ret = c_ret + Chr(17)
  214.                Case c_upper = '/BEEP' .or. c_upper='/BELL'
  215.                   c_ret = c_ret + Chr(7)
  216.                Case c_upper = '/CAN'
  217.                   c_ret = c_ret + Chr(24)
  218.             Endcase
  219.  
  220.          Endif
  221.  
  222.       Endif
  223.  
  224.       c_st = At(",",Substr(c_nums,c_st+1))+c_st
  225.       c_part = Substr(c_nums,c_st+1,At(",",Substr(c_nums,c_st+2)))
  226.  
  227.    Enddo
  228.  
  229. Return c_ret
  230.